package com.cms.web.dict;

import java.sql.Timestamp;
import java.util.Date;

import javax.servlet.http.HttpSession;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import com.cms.biz.dict.CMSContractServiceMgr;
import com.cms.persistence.constratInfo.FKFSZD;
import com.cms.persistence.constratInfo.HTCPZD;
import com.cms.persistence.constratInfo.HTXMZD;
import com.cms.persistence.constratInfo.JSFSZD;
import com.cms.persistence.constratInfo.PSSXZD;
import com.cms.pub.HTXMDataSet2JsonUtil;
import com.web.BaseController;
import com.efounder.builder.base.data.EFDataSet;
import com.efounder.builder.base.data.EFRowSet;
import com.efounder.builder.util.EMPRowSetUtil;
import com.efounder.dict.DMTServiceMgr;
import com.efounder.eai.data.JParamObject;
import com.efounder.eai.data.JResponseObject;
import com.metadata.biz.MetaDataServiceMgr;
import com.mrp.persistence.queryAnalyse.pageQuery.bean.EMPPageQuery;
import com.persistence.qxgl.beans.SYSUser;

@Controller
@RequestMapping(value="/cmsContractInfo")
public class ContractInfoController extends BaseController{
	@Autowired
	private                            DMTServiceMgr                     DMTServiceMgr;
	
	@Autowired
	public                               HttpSession                           session;

	@Autowired
	public                        MetaDataServiceMgr                   metaDataService;
	
	@Autowired
	public                     CMSContractServiceMgr                   contractService;
	
	/**
	 * 评审事项列表
	 * @param model
	 * @return
	 */
	@RequestMapping("/accreditationMatters")
	public String accreditationMattersList(Model model) {	
		EFDataSet dataset = DMTServiceMgr.searchDictRow("PSSXZD", "F_PSBH", "", null, 0, 100);
		model.addAttribute("dataset", dataset);
		return "/cms/dict/pssx/list";
	}
	
	/**
	 * 评审事项列表
	 * @param model
	 * @return
	 */
	@RequestMapping("/accreditationMatters/list")
	public String accreditationMattersList(@RequestParam String keywords, Model model) {	
		EFDataSet dataset = DMTServiceMgr.searchDictRow("PSSXZD", "F_PSMS", keywords, null, 0, 100);
		model.addAttribute("dataset", dataset);
		model.addAttribute("keywords", keywords);
		return "/cms/dict/pssx/list";
	}
	
	/**
	 * 评审事项添加
	 * @param model
	 * @return
	 */
	@RequestMapping("/accreditationMatters/add")
	public String accreditationMattersAdd(Model model) {	
		String tempBh = DMTServiceMgr.getTempDictBM("PSSXZD");
		EFRowSet rowset = EFRowSet.getInstance();
		rowset.putString("F_PSBH", tempBh);
		model.addAttribute("dictObject", rowset);
		return "/cms/dict/pssx/add";
	}
	
	/**
	 * 评审事项添加保存
	 * @param sxzd
	 * @return
	 */
	@RequestMapping(value = "/accreditationMatters/insert", method = RequestMethod.POST)
	public ModelAndView accreditationMattersInsert(PSSXZD sxzd) {	
		EFRowSet rowset;
		try {
			rowset = EMPRowSetUtil.createRowSet(sxzd);
		} catch (Exception e) {
			e.printStackTrace();
			return ajaxDoneError(e.getMessage());
		}
		JResponseObject RO = DMTServiceMgr.insertDCTRow("PSSXZD", rowset);
		if(RO.getErrorCode() == -1) {
			return ajaxDoneError(RO.getErrorString());
		} else {
			return ajaxDoneSuccess(RO.ResponseObject.toString());
		}
	}
	
	/**
	 * 评审事项编辑
	 * @param model
	 * @return
	 */
	@RequestMapping("/accreditationMatters/edit/{F_PSBH}")
	public String accreditationMattersEdit(@PathVariable("F_PSBH") String F_PSBH, Model model) {
		EFRowSet rowset = DMTServiceMgr.getRow("PSSXZD", F_PSBH);
		model.addAttribute("dictObject", rowset);
		return "/cms/dict/pssx/edit";
	}
	
	/**
	 * 评审事项编辑保存
	 * @param model
	 * @return
	 */
	@RequestMapping("/accreditationMatters/update")
	public ModelAndView accreditationMattersUpdate(PSSXZD sxzd, Model model) {
		EFRowSet rowset = DMTServiceMgr.getRow("PSSXZD", sxzd.getF_PSBH());
		rowset.putString("F_PSMS", sxzd.getF_PSMS());
		rowset.putString("F_SYZT", sxzd.getF_SYZT());
		JResponseObject RO = DMTServiceMgr.updateRow("PSSXZD", rowset);
		if(RO.getErrorCode() == -1) {
			return ajaxDoneError(RO.getErrorString());
		} else {
			return ajaxDoneSuccess(RO.ResponseObject.toString());
		}
	}
	
	/**
	 * 评审事项删除
	 * @param F_ZDBH
	 * @return
	 */
	@RequestMapping("/accreditationMatters/delete/{F_ZDBH}")
	public ModelAndView accreditationMattersDelete(@PathVariable("F_ZDBH") String F_ZDBH) {	
		JResponseObject RO = DMTServiceMgr.deleteRow("PSSXZD", F_ZDBH);
		if(RO.getErrorCode() == -1) {
			return ajaxDoneError(RO.getErrorString());
		} else {
			return ajaxDoneSuccess(RO.ResponseObject.toString());
		}
	}
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	/**
	 * 付款方式列表
	 * @param model
	 * @return
	 */
	@RequestMapping("/payment")
	public String paymentList(Model model) {	
		EFDataSet dataset = DMTServiceMgr.searchDictRow("FKFSZD", "F_FKBH", "", null, 0, 100);
		model.addAttribute("dataset", dataset);
		return "/cms/dict/fkfs/list";
	}
	
	/**
	 * 付款方式列表
	 * @param model
	 * @return
	 */
	@RequestMapping("/payment/list")
	public String paymentList(@RequestParam String keywords, Model model) {	
		EFDataSet dataset = DMTServiceMgr.searchDictRow("FKFSZD", "F_FKMC", keywords, null, 0, 100);
		model.addAttribute("dataset", dataset);
		model.addAttribute("keywords", keywords);
		return "/cms/dict/fkfs/list";
	}
	
	/**
	 * 付款方式添加
	 * @param model
	 * @return
	 */
	@RequestMapping("/payment/add")
	public String paymentAdd(Model model) {	
		String tempBh = DMTServiceMgr.getTempDictBM("FKFSZD");
		EFRowSet rowset = EFRowSet.getInstance();
		rowset.putString("F_FKBH", tempBh);
		model.addAttribute("dictObject", rowset);
		return "/cms/dict/fkfs/add";
	}
	
	/**
	 * 付款方式添加保存
	 * @param fszd
	 * @return
	 */
	@RequestMapping(value = "/payment/insert", method = RequestMethod.POST)
	public ModelAndView paymentInsert(FKFSZD fszd) {	
		EFRowSet rowset;
		try {
			rowset = EMPRowSetUtil.createRowSet(fszd);
		} catch (Exception e) {
			e.printStackTrace();
			return ajaxDoneError(e.getMessage());
		}
		JResponseObject RO = DMTServiceMgr.insertDCTRow("FKFSZD", rowset);
		if(RO.getErrorCode() == -1) {
			return ajaxDoneError(RO.getErrorString());
		} else {
			return ajaxDoneSuccess(RO.ResponseObject.toString());
		}
	}
	
	/**
	 * 付款方式编辑
	 * @param model
	 * @return
	 */
	@RequestMapping("/payment/edit/{F_ZDBH}")
	public String paymentEdit(@PathVariable("F_ZDBH") String F_ZDBH, Model model) {
		EFRowSet rowset = DMTServiceMgr.getRow("FKFSZD", F_ZDBH);
		model.addAttribute("dictObject", rowset);
		return "/cms/dict/fkfs/edit";
	}
	
	/**
	 * 付款方式编辑保存
	 * @param model
	 * @return
	 */
	@RequestMapping("/payment/update")
	public ModelAndView paymentUpdate(FKFSZD fszd, Model model) {
		EFRowSet rowset = DMTServiceMgr.getRow("FKFSZD", fszd.getF_FKBH());
		rowset.putString("F_FKMC", fszd.getF_FKMC());
		rowset.putString("F_SYZT", fszd.getF_SYZT());
		JResponseObject RO = DMTServiceMgr.updateRow("FKFSZD", rowset);
		if(RO.getErrorCode() == -1) {
			return ajaxDoneError(RO.getErrorString());
		} else {
			return ajaxDoneSuccess(RO.ResponseObject.toString());
		}
	}
	
	/**
	 * 付款方式删除
	 * @param model
	 * @return
	 */
	@RequestMapping("/payment/delete/{F_ZDBH}")
	public ModelAndView paymentDelete(@PathVariable("F_ZDBH") String F_ZDBH) {	
		JResponseObject RO = DMTServiceMgr.deleteRow("FKFSZD", F_ZDBH);
		if(RO.getErrorCode() == -1) {
			return ajaxDoneError(RO.getErrorString());
		} else {
			return ajaxDoneSuccess(RO.ResponseObject.toString());
		}
	}
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	

	/**
	 * 结算方式列表
	 * @param model
	 * @return
	 */
	@RequestMapping("/settlement")
	public String settlementList(Model model) {	
		EFDataSet dataset = DMTServiceMgr.searchDictRow("JSFSZD", "F_JSBH", "", null, 0, 100);
		model.addAttribute("dataset", dataset);
		return "/cms/dict/jsfs/list";
	}
	
	/**
	 * 结算方式列表
	 * @param model
	 * @return
	 */
	@RequestMapping("/settlement/list")
	public String settlementList(@RequestParam String keywords, Model model) {	
		EFDataSet dataset = DMTServiceMgr.searchDictRow("JSFSZD", "F_JSMC", keywords, null, 0, 100);
		model.addAttribute("dataset", dataset);
		model.addAttribute("keywords", keywords);
		return "/cms/dict/jsfs/list";
	}
	
	/**
	 * 结算方式添加
	 * @param model
	 * @return
	 */
	@RequestMapping("/settlement/add")
	public String settlementAdd(Model model) {	
		String tempBh = DMTServiceMgr.getTempDictBM("JSFSZD");
		EFRowSet rowset = EFRowSet.getInstance();
		rowset.putString("F_JSBH", tempBh);
		model.addAttribute("dictObject", rowset);
		return "/cms/dict/jsfs/add";
	}
	
	/**
	 * 结算方式添加保存
	 * @param model
	 * @return
	 */
	@RequestMapping(value = "/settlement/insert", method = RequestMethod.POST)
	public ModelAndView settlementInsert(JSFSZD jszd) {	
		EFRowSet rowset;
		try {
			rowset = EMPRowSetUtil.createRowSet(jszd);
		} catch (Exception e) {
			e.printStackTrace();
			return ajaxDoneError(e.getMessage());
		}
		JResponseObject RO = DMTServiceMgr.insertDCTRow("JSFSZD", rowset);
		if(RO.getErrorCode() == -1) {
			return ajaxDoneError(RO.getErrorString());
		} else {
			return ajaxDoneSuccess(RO.ResponseObject.toString());
		}
	}
	
	/**
	 * 结算方式编辑
	 * @param model
	 * @return
	 */
	@RequestMapping("/settlement/edit/{F_ZDBH}")
	public String settlementEdit(@PathVariable("F_ZDBH") String F_ZDBH, Model model) {
		EFRowSet rowset = DMTServiceMgr.getRow("JSFSZD", F_ZDBH);
		model.addAttribute("dictObject", rowset);
		return "/cms/dict/jsfs/edit";
	}
	
	/**
	 * 结算方式编辑保存
	 * @param model
	 * @return
	 */
	@RequestMapping("/settlement/update")
	public ModelAndView settlementUpdate(JSFSZD jszd, Model model) {
		EFRowSet rowset = DMTServiceMgr.getRow("JSFSZD", jszd.getF_JSBH());
		rowset.putString("F_JSMC", jszd.getF_JSMC());
		rowset.putString("F_SYZT", jszd.getF_SYZT());
		JResponseObject RO = DMTServiceMgr.updateRow("JSFSZD", rowset);
		if(RO.getErrorCode() == -1) {
			return ajaxDoneError(RO.getErrorString());
		} else {
			return ajaxDoneSuccess(RO.ResponseObject.toString());
		}
	}
	
	/**
	 * 结算方式删除
	 * @param model
	 * @return
	 */
	@RequestMapping("/settlement/delete/{F_ZDBH}")
	public ModelAndView settlementDelete(@PathVariable("F_ZDBH") String F_ZDBH) {	
		JResponseObject RO = DMTServiceMgr.deleteRow("JSFSZD", F_ZDBH);
		if(RO.getErrorCode() == -1) {
			return ajaxDoneError(RO.getErrorString());
		} else {
			return ajaxDoneSuccess(RO.ResponseObject.toString());
		}
	}
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	/**
	 * 合同项目列表
	 * @param model
	 * @return
	 */
	@RequestMapping("/contractProject")
	public String contractProjectList(@RequestParam String pageRowCount, Model model) {	
		JParamObject     PO = JParamObject.Create();
    	String         json = "";
    	EFDataSet   dataset = null;
    	
    	json = loadProjectTree();
    	dataset = loadProjectList(PO, pageRowCount, model);
    	
        model.addAttribute("dataset", dataset);
        model.addAttribute("treeJson", json);
        
		return "/cms/dict/htxm/tree";
	}
	
	/**
	 * 合同项目列表
	 * @param model
	 * @return
	 */
	@RequestMapping("/contractProject/list")
	public String contractProjectList2(@RequestParam String F_XMBH, Model model) {	
		EFDataSet dataset = DMTServiceMgr.searchDictRow("HTXMZD", "F_XMMC", F_XMBH, null, 0, 100);
		model.addAttribute("dataset", dataset);
		model.addAttribute("F_XMBH", F_XMBH);
		return "/cms/dict/htxm/list";
	}
	
	/**
     * 合同项目列表
     * @param model
     * @return
     */
    @RequestMapping("/contractProject/list/search")
    public String searchProjectList(@RequestParam String F_XMBH, @RequestParam String F_XMMC, @RequestParam String pageRowCount, EMPPageQuery page, Model model) {
    	JParamObject     PO = JParamObject.Create();

    	PO.SetValueByParamName("COLUMN_EXTEND", "FXCBXX_V.F_FPJEHJ");
    	PO.SetValueByParamName("SQL_LEFTJOIN", " left join FXCBXX_V on HTXMZD.F_XMBH = FXCBXX_V.F_XMBH");
    	
    	searchProjectList(PO, F_XMBH, F_XMMC, pageRowCount, page, model);
        
        return "/cms/dict/htxm/list";
    }
    
    /**
     * 合同项目列表
     * @param model
     * @return
     */
    @RequestMapping("/contractProject/list/pageSearch")
    public String searchPageProjectList(@RequestParam String F_XMBH, @RequestParam String F_XMMC, @RequestParam String pageRowCount, EMPPageQuery page, Model model) {
    	JParamObject     PO = JParamObject.Create();

    	PO.SetValueByParamName("COLUMN_EXTEND", "FXCBXX_V.F_FPJEHJ");
    	PO.SetValueByParamName("SQL_LEFTJOIN", " left join FXCBXX_V on HTXMZD.F_XMBH = FXCBXX_V.F_XMBH");
    	
    	searchProjectList(PO, F_XMBH, F_XMMC, pageRowCount, page, model);
        
        return "/cms/dict/htxm/list";
    }
    
	/**
     * 加载项目树形菜单数据
     * @return
     */
    public String loadProjectTree() {    	
    	JParamObject            PO = JParamObject.Create();
		JSONObject      jsonObject = new JSONObject();
		JSONObject     jsonObject1 = new JSONObject();
		JSONArray          jsonArr = new JSONArray();//json格式的数组
		JSONArray         jsonArr1 = new JSONArray();//json格式的数组
		EFDataSet          dataset = EFDataSet.getInstance();
		EFRowSet        dictRowSet = EFRowSet.getInstance();

		PO.SetValueByParamName("tableName", "HTXMZD");
		PO.SetValueByParamName("searchCol", "F_XMBH");
		PO.SetValueByParamName("keywords", "");
		PO.SetValueByParamName("F_SYZT", null);
		PO.SetValueByParamName("sqlWhere", " F_MX = '0'");
		PO.SetValueByParamName("sqlOrderBy", "F_XMBH, F_JS");
		
		dataset = DMTServiceMgr.searchDictRow(PO);
		dictRowSet = metaDataService.getDictRow("HTXMZD");
		
		jsonObject = HTXMDataSet2JsonUtil.convertDataSet2Json(dataset, dictRowSet);
		jsonArr = jsonObject.getJSONArray("data");
		jsonObject1.put("text", "合同项目信息");
		jsonObject1.put("F_XMBH", "");
		jsonObject1.put("icon", "a");
		jsonObject1.put("children", jsonArr);
		jsonArr1.add(jsonObject1);
		String json = jsonArr1.toString();
		json = json.replace("\"icon\":\"a\"", "icon:a").replace("\"icon\":\"b\"", "icon:b").replace("\"icon\":\"c\"", "icon:c").replace("\"icon\":\"d\"", "icon:d");
		json = json.replace("\"icon\":\"e\"", "icon:e").replace("\"icon\":\"f\"", "icon:f").replace("\"icon\":\"g\"", "icon:g");
		System.out.println(json);

        return json;
    }
    
    /**
     * 加载项目列表数据
     * @param model
     * @return
     */
    public EFDataSet loadProjectList(JParamObject PO, String pageRowCount, Model model) {    	
        EFRowSet            rowset = null;
        String          BILL_WHERE = "";
        EMPPageQuery          page = new EMPPageQuery();
        
    	//查找第一級
        BILL_WHERE = "HTXMZD.F_JS = 1 and HTXMZD.F_SYZT = '1'";
        PO.SetValueByParamName("tableName", "HTXMZD");
        PO.SetValueByParamName("searchCol", "HTXMZD.F_XMBH");
        PO.SetValueByParamName("keywords", "");
        PO.SetValueByParamName("F_SYZT", null);
        PO.SetValueByParamName("sqlWhere", BILL_WHERE);
        PO.SetValueByParamName("sqlOrderBy", "HTXMZD.F_XMBH, HTXMZD.F_JS");
        PO.SetValueByParamName("pageNumber", "1");
        PO.SetValueByParamName("pageRowCount", pageRowCount);
        
        rowset = DMTServiceMgr.searchDictPageRows(PO);

        page.setNumPerPage(Integer.parseInt(pageRowCount));
        
        if(rowset.getNumber("rowCount", 0) == null) {
        	page.setTotalCount(0);
        } else {
        	page.setTotalCount(rowset.getNumber("rowCount", 0).intValue());
        }
        
        if(rowset.getNumber("pageCount", 0) == null) {
        	page.setPageNumShown(1);
        } else {
        	page.setPageNumShown(rowset.getNumber("pageCount", 0).intValue());
        }
        
        model.addAttribute("page", page);
        
        return rowset.getDataSet("HTXMZD");
    }
    
    /**
     * 合同项目列表
     * @param model
     * @return
     */
    public String searchProjectList(JParamObject PO, String F_XMBH, String F_XMMC, String pageRowCount, EMPPageQuery page, Model model) {    	
        String          BILL_WHERE = "";
        EFRowSet        dictRowSet = null;
        int                   F_JS = 0;
        EFRowSet            rowset = null;
        int          iPageRowCount = 0;
    	
    	try {
    		iPageRowCount = Integer.parseInt(pageRowCount);
    	} catch(Exception ce) {
    		iPageRowCount = 50;
    	}
    	
    	page.setNumPerPage(iPageRowCount);
    	
    	//查找第一級
        if(F_XMBH.trim().equals("")) {
        	BILL_WHERE = "HTXMZD.F_JS = 1 and HTXMZD.F_XMBH like '%" + F_XMBH + "%' and HTXMZD.F_XMMC like '%" + F_XMMC + "%'";
        } else {
        	dictRowSet = DMTServiceMgr.getRow("HTXMZD", "F_XMBH", F_XMBH);
            F_JS = dictRowSet.getNumber("F_JS", 0).intValue();
            BILL_WHERE = "HTXMZD.F_XMBH like '" + F_XMBH + "%' and HTXMZD.F_XMMC like '%" + F_XMMC + "%' and HTXMZD.F_JS = " + (F_JS + 1);
        }
        
        PO.SetValueByParamName("tableName", "HTXMZD");
        PO.SetValueByParamName("searchCol", "HTXMZD.F_XMMC");
        PO.SetValueByParamName("keywords", F_XMMC);
        PO.SetValueByParamName("F_SYZT", null);
        PO.SetValueByParamName("sqlWhere", BILL_WHERE);
        PO.SetValueByParamName("sqlOrderBy", "HTXMZD.F_XMBH, HTXMZD.F_JS");
        PO.SetValueByParamName("pageNumber", String.valueOf(page.getPageNum()));
        PO.SetValueByParamName("pageRowCount", String.valueOf(page.getNumPerPage()));
        
        rowset = DMTServiceMgr.searchDictPageRows(PO);
        
        page.setPageNumShown(rowset.getNumber("pageCount", 1).intValue());
        page.setTotalCount(rowset.getNumber("rowCount", 1).intValue());
        
        model.addAttribute("page", page);
        model.addAttribute("dataset", rowset.getDataSet("HTXMZD"));
        model.addAttribute("F_XMBH", F_XMBH);
        model.addAttribute("F_XMMC", F_XMMC);
        
        return "";
    }
    
	/**
	 * 合同项目列表
	 * @param model
	 * @return
	 */
	@RequestMapping("/contractProject/nextList")
	public String contractProjectNextList(@RequestParam String F_XMBH, @RequestParam String pageRowCount, Model model) {	
		EFDataSet       dataset = null;
        EFRowSet     dictRowSet = null;
        EFRowSet         rowset = null;
        int                F_JS = 0;
        String       BILL_WHERE = "";
        EMPPageQuery       page = new EMPPageQuery();
        JParamObject         PO = JParamObject.Create();
        
        dictRowSet = DMTServiceMgr.getRow("HTXMZD", "HTXMZD.F_XMBH", F_XMBH);
        F_JS = dictRowSet.getNumber("F_JS", 0).intValue();
        BILL_WHERE = "HTXMZD.F_XMBH like '" + F_XMBH + "%' and HTXMZD.F_JS = " + (F_JS + 1);
        PO.SetValueByParamName("tableName", "HTXMZD");
        PO.SetValueByParamName("searchCol", "HTXMZD.F_XMBH");
        PO.SetValueByParamName("keywords", "");
        PO.SetValueByParamName("F_SYZT", null);
        PO.SetValueByParamName("sqlWhere", BILL_WHERE);
        PO.SetValueByParamName("sqlOrderBy", "HTXMZD.F_XMBH, HTXMZD.F_JS");
        PO.SetValueByParamName("isPage", "1");
        PO.SetValueByParamName("pageNumber", "1");
        PO.SetValueByParamName("pageRowCount", pageRowCount);
        
        rowset = DMTServiceMgr.searchDictPageRows(PO);

        dataset = rowset.getDataSet("HTXMZD");
        
        if(rowset.getNumber("rowCount", 0) == null) {
        	page.setTotalCount(0);
        } else {
        	page.setTotalCount(rowset.getNumber("rowCount", 0).intValue());
        }
        
        if(rowset.getNumber("pageCount", 0) == null) {
        	page.setPageNumShown(0);
        } else {
        	page.setPageNumShown(rowset.getNumber("pageCount", 0).intValue());
        }
        
        model.addAttribute("page", page);
        
        model.addAttribute("dataset", dataset);
        model.addAttribute("F_XMBH", F_XMBH);
        
		return "/cms/dict/htxm/list";
	}
	
	/**
	 * 合同项目添加
	 * @param model
	 * @return
	 */
	@RequestMapping("/contractProject/add")
	public String contractProjectAdd(@RequestParam String F_XMBH, Model model) {
		String tempBh = DMTServiceMgr.getTempDictBM("HTXMZD");
		EFRowSet     dictRowSet = null;
		int                F_JS = 0;
		dictRowSet = DMTServiceMgr.getRow("HTXMZD", "F_XMBH", F_XMBH);
		F_JS = dictRowSet.getNumber("F_JS", 0).intValue();
		EFRowSet rowset = EFRowSet.getInstance();
		rowset.putString("F_XMBH", tempBh);
		rowset.putString("F_JS", String.valueOf(F_JS + 1));
		rowset.putString("PARENT_XMBH", F_XMBH);
		model.addAttribute("dictObject", rowset);
		return "/cms/dict/htxm/add";
	}

	/**
	 * 合同项目添加保存
	 * @param model
	 * @return
	 */
	@RequestMapping(value = "/contractProject/insert", method = RequestMethod.POST)
	public ModelAndView contractProjectInsert(@RequestParam String PARENT_XMBH, HTXMZD htxm) {	
		EFRowSet         rowset;
		EFRowSet     dictRowSet = null;
		String             F_MX = "";
		JParamObject         PO = JParamObject.Create();
		SYSUser            user = (SYSUser) session.getAttribute("contextUser");
		
		dictRowSet = DMTServiceMgr.getRow("HTXMZD", "F_XMBH", PARENT_XMBH);
		F_MX = dictRowSet.getString("F_MX", "1");
		
		if(F_MX.equals("1") && !PARENT_XMBH.equals("")) {
			return ajaxDoneError("[" + dictRowSet.getString("F_XMBH", "") + "-" + dictRowSet.getString("F_XMMC", "") + "]为明细项目，不允许添加下级项目！");
		}
		try {
			rowset = EMPRowSetUtil.createRowSet(htxm);
		} catch (Exception e) {
			e.printStackTrace();
			return ajaxDoneError(e.getMessage());
		}
		
		PO.SetValueByParamName("DCI_ID", "HTXMZD");
		PO.SetValueByParamName("PARENT_XMBH", PARENT_XMBH);
		
		try {
			htxm.setF_CHDATE(new Timestamp(System.currentTimeMillis()));
			htxm.setF_CRDATE(new Timestamp(System.currentTimeMillis()));
			htxm.setF_LRR(user.getUSER_ID());
			rowset = EMPRowSetUtil.createRowSet(htxm);
		} catch (Exception e) {
			e.printStackTrace();
			return ajaxDoneError(e.getMessage());
		}
		
		JResponseObject RO = contractService.insertHTXM(PO, rowset);
		
		if(RO.getErrorCode() == -1) {
			return ajaxDoneError(RO.getErrorString());
		} else {
			return ajaxDoneSuccess(RO.ResponseObject.toString());
		}
	}
	
	/**
	 * 合同项目编辑
	 * @param model
	 * @return
	 */
	@RequestMapping("/contractProject/edit/{F_XMBH}")
	public String contractProjectEdit(@PathVariable("F_XMBH") String F_XMBH, Model model) {
		EFRowSet rowset = DMTServiceMgr.getRow("HTXMZD", F_XMBH);
		model.addAttribute("dictObject", rowset);
		return "/cms/dict/htxm/edit";
	}
	
	/**
	 * 合同项目编辑保存
	 * @param model
	 * @return
	 */
	@RequestMapping("/contractProject/update")
	public ModelAndView contractProjectUpdate(HTXMZD htxm, Model model) {
		EFRowSet rowset = DMTServiceMgr.getRow("HTXMZD", htxm.getF_XMBH());
		rowset.putString("F_XMMC", htxm.getF_XMMC());
		rowset.putString("F_JS", String.valueOf(htxm.getF_JS()));
		rowset.putString("F_MX", htxm.getF_MX());
		rowset.putString("F_SYZT", htxm.getF_SYZT());
		rowset.putString("F_NOTE", htxm.getF_NOTE());
		rowset.putObject("F_CHDATE", new Date());
		
		JResponseObject RO = DMTServiceMgr.updateRow("HTXMZD", rowset);
		if(RO.getErrorCode() == -1) {
			return ajaxDoneError(RO.getErrorString());
		} else {
			return ajaxDoneSuccess(RO.ResponseObject.toString());
		}
	}
	
	/**
	 * 合同项目删除
	 * @param model
	 * @return
	 */
	@RequestMapping("/contractProject/delete/{F_ZDBH}")
	public ModelAndView contractProjectDelete(@PathVariable("F_ZDBH") String F_ZDBH) {	
		JResponseObject RO = DMTServiceMgr.deleteRow("HTXMZD", F_ZDBH);
		if(RO.getErrorCode() == -1) {
			return ajaxDoneError(RO.getErrorString());
		} else {
			return ajaxDoneSuccess(RO.ResponseObject.toString());
		}
	}


	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	/**
	 * 合同产品列表
	 * @param model
	 * @return
	 */
	@RequestMapping("/contractProduct")
	public String contractProductList(@RequestParam String pageRowCount, Model model) {	
		JParamObject            PO = JParamObject.Create();
		EFRowSet            rowset = null;
        EMPPageQuery          page = new EMPPageQuery();
        
        rowset = searchProductList(PO, "", pageRowCount, page, model);
        
        page.setNumPerPage(Integer.parseInt(pageRowCount));
        
        if(rowset.getNumber("rowCount", 0) == null) {
        	page.setTotalCount(0);
        } else {
        	page.setTotalCount(rowset.getNumber("rowCount", 0).intValue());
        }
        
        if(rowset.getNumber("pageCount", 0) == null) {
        	page.setPageNumShown(1);
        } else {
        	page.setPageNumShown(rowset.getNumber("pageCount", 0).intValue());
        }

		return "/cms/dict/htcp/list";
	}
	
	/**
	 * 合同产品列表
	 * @param model
	 * @return
	 */
	@RequestMapping("/contractProduct/list")
	public String contractProductList(@RequestParam String keyword, @RequestParam String pageRowCount, EMPPageQuery page, Model model) {	
		JParamObject            PO = JParamObject.Create();
		EFRowSet            rowset = null;
        
        rowset = searchProductList(PO, keyword, pageRowCount, page, model);
        
        page.setNumPerPage(Integer.parseInt(pageRowCount));
        
        if(rowset.getNumber("rowCount", 0) == null) {
        	page.setTotalCount(0);
        } else {
        	page.setTotalCount(rowset.getNumber("rowCount", 0).intValue());
        }
        
        if(rowset.getNumber("pageCount", 0) == null) {
        	page.setPageNumShown(1);
        } else {
        	page.setPageNumShown(rowset.getNumber("pageCount", 0).intValue());
        }
        
        model.addAttribute("keyword", keyword);
        
		return "/cms/dict/htcp/list";
	}
	
	/**
     * 合同项目列表
     * @param model
     * @return
     */
    @RequestMapping("/contractProduct/list/pageSearch")
    public String contractProductListPageSearch(@RequestParam String F_CPMC, @RequestParam String pageRowCount, EMPPageQuery page, Model model) {	
    	JParamObject            PO = JParamObject.Create();
		EFRowSet            rowset = null;
        
        rowset = searchProductList(PO, F_CPMC, pageRowCount, page, model);
        
        page.setNumPerPage(Integer.parseInt(pageRowCount));
        
        if(rowset.getNumber("rowCount", 0) == null) {
        	page.setTotalCount(0);
        } else {
        	page.setTotalCount(rowset.getNumber("rowCount", 0).intValue());
        }
        
        if(rowset.getNumber("pageCount", 0) == null) {
        	page.setPageNumShown(1);
        } else {
        	page.setPageNumShown(rowset.getNumber("pageCount", 0).intValue());
        }
        
        return "/cms/dict/htcp/list";
    }
    
	public EFRowSet searchProductList(JParamObject PO, String F_CPMC, String pageRowCount, EMPPageQuery page, Model model) {
        EFRowSet            rowset = null;
        int          iPageRowCount = 0;
    	
    	try {
    		iPageRowCount = Integer.parseInt(pageRowCount);
    	} catch(Exception ce) {
    		iPageRowCount = 50;
    	}
    	
    	page.setNumPerPage(iPageRowCount);
 
        
        PO.SetValueByParamName("tableName", "HTCPZD");
        PO.SetValueByParamName("searchCol", "HTCPZD.F_CPMC");
        PO.SetValueByParamName("keywords", F_CPMC);
        PO.SetValueByParamName("F_SYZT", null);
        PO.SetValueByParamName("sqlWhere", " F_CPMC like '%" + F_CPMC + "%'");
        PO.SetValueByParamName("sqlOrderBy", "HTCPZD.F_CPBH");
        PO.SetValueByParamName("pageNumber", String.valueOf(page.getPageNum()));
        PO.SetValueByParamName("pageRowCount", String.valueOf(page.getNumPerPage()));
        
        rowset = DMTServiceMgr.searchDictPageRows(PO);
        
        page.setPageNumShown(rowset.getNumber("pageCount", 1).intValue());
        page.setTotalCount(rowset.getNumber("rowCount", 1).intValue());
        
        model.addAttribute("page", page);
        model.addAttribute("dataset", rowset.getDataSet("HTCPZD"));
        model.addAttribute("F_CPMC", F_CPMC);
        
        return rowset;
	}
	
	/**
	 * 合同产品添加
	 * @param model
	 * @return
	 */
	@RequestMapping("/contractProduct/add")
	public String contractProductAdd(Model model) {	
		String tempBh = DMTServiceMgr.getTempDictBM("HTCPZD");
		EFRowSet rowset = EFRowSet.getInstance();
		rowset.putString("F_CPBH", tempBh);
		model.addAttribute("dictObject", rowset);
		return "/cms/dict/htcp/add";
	}
	
	/**
	 * 合同产品添加保存
	 * @param model
	 * @return
	 */
	@RequestMapping(value = "/contractProduct/insert", method = RequestMethod.POST)
	public ModelAndView contractProductInsert(HTCPZD cpzd) {	
		EFRowSet rowset;
		try {
			rowset = EMPRowSetUtil.createRowSet(cpzd);
		} catch (Exception e) {
			e.printStackTrace();
			return ajaxDoneError(e.getMessage());
		}
		JResponseObject RO = DMTServiceMgr.insertDCTRow("HTCPZD", rowset);
		if(RO.getErrorCode() == -1) {
			return ajaxDoneError(RO.getErrorString());
		} else {
			return ajaxDoneSuccess(RO.ResponseObject.toString());
		}
	}
	
	/**
	 * 合同产品编辑
	 * @param model
	 * @return
	 */
	@RequestMapping("/contractProduct/edit/{F_ZDBH}")
	public String contractProductEdit(@PathVariable("F_ZDBH") String F_ZDBH, Model model) {
		EFRowSet rowset = DMTServiceMgr.getRow("HTCPZD", F_ZDBH);
		model.addAttribute("dictObject", rowset);
		return "/cms/dict/htcp/edit";
	}
	
	/**
	 * 合同产品编辑保存
	 * @param model
	 * @return
	 */
	@RequestMapping("/contractProduct/update")
	public ModelAndView contractProductUpdate(HTCPZD cpzd, Model model) {
		EFRowSet rowset = DMTServiceMgr.getRow("HTCPZD", cpzd.getF_CPBH());
		try {
			rowset = EMPRowSetUtil.createRowSet(cpzd);
		} catch (Exception e) {
			e.printStackTrace();
			return ajaxDoneError(e.getMessage());
		}
		rowset.putString("F_CPBH", cpzd.getF_CPBH());
		JResponseObject RO = DMTServiceMgr.updateRow("HTCPZD", rowset);
		if(RO.getErrorCode() == -1) {
			return ajaxDoneError(RO.getErrorString());
		} else {
			return ajaxDoneSuccess(RO.ResponseObject.toString());
		}
	}
	
	/**
	 * 合同产品删除
	 * @param model
	 * @return
	 */
	@RequestMapping("/contractProduct/delete/{F_ZDBH}")
	public ModelAndView contractProductDelete(@PathVariable("F_ZDBH") String F_ZDBH) {	
		JResponseObject RO = DMTServiceMgr.deleteRow("HTCPZD", F_ZDBH);
		if(RO.getErrorCode() == -1) {
			return ajaxDoneError(RO.getErrorString());
		} else {
			return ajaxDoneSuccess(RO.ResponseObject.toString());
		}
	}
}
